<!--
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-06-06 16:02:37
 * @LastEditTime: 2021-06-06 16:39:01
-->
<script>
    // 试输出斐波那契数列的前10项，即1、1、2、3、5、8、13、21、34、55

    {
        let cache = {};

        function fib(n) {
            let result;
            if (cache.hasOwnProperty(n)) {
                return cache[n];
            }

            if (n == 0 || n == 1) return 1;
            return cache[n] = result = ((n == 0 || n == 1)) ? 1 : fib(n - 1) + fib(n - 2);
        };
    }


    {
        function fibe1(n) {
            let arr = [1, 1];
            while (arr.length <= n) {
                arr.push(arr[arr.length - 1] + arr[arr.length - 2]);
            }
            return arr;

        };

        let result = fibe1(6);
        console.log(result);

    }
</script>